<?php
namespace Users\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Expression;
class SubscribeTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function addSubscriber($email)
    {
		$data = array(
			'user_email' 		=> $email,  
			'status' 		=> 1, 
			'added_date' 	=> date('Y-m-d H:i:s'),   
			'updated_date'	=> date('Y-m-d H:i:s'), 	
		);
		
		$this->tableGateway->insert($data);	
		
		return $this->tableGateway->lastInsertValue;
    }
	public function checkEmail($email){
		$select = $this->tableGateway->getSql()->select();			
		$select->where('user_email="'.$email.'"');	
		$resultSet = $this->tableGateway->selectWith($select);
		$row=$resultSet->count();	
		return $row;		
	}
	public function allSubScribers(){
		$select = $this->tableGateway->getSql()->select();
		$select->where('status=1');	
		$resultSet = $this->tableGateway->selectWith($select);	
		return $resultSet;
	}
	public function updateSubScriberMailStatus($email){
		$data = array(
			'status'       =>0,
		);
		$updateSubScriberStatus=$this->tableGateway->update($data,array('(user_email IN ('.$email.'))'));
		return 	$updateSubScriberStatus;			
	}
	
}